import Vue from 'vue'
import VueRouter from 'vue-router'
const homes = () =>
    import ('../view/home.vue')
const abouts = () =>
    import ('../view/about.vue')

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}

Vue.use(VueRouter)

const router = new VueRouter({
    routes: [{
            path: '',
            redirect: '/home'
        }, {
            path: '/home',
            component: homes,
            meta: {
                title: 'home'
            },
            children: [{
                path: 'abc',
                meta: {
                    title: 'abc'
                },
                component: () =>
                    import ('../view/abc.vue')
            }, {
                path: 'def',
                meta: {
                    title: 'def'
                },
                component: () =>
                    import ('../view/def.vue')
            }]
        },
        {
            path: '/about',
            component: abouts,
            meta: {
                title: 'about'
            },
        }
    ],
    linkActiveClass: 'active',
    mode: 'history'
})
router.beforeEach((to, from, next) => {
    window.document.title = to.meta.title;
    next();
})

export default router